/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ez2find.manager;

import com.ez2find.model.CategoriaInmobiliario;
import com.ez2find.model.HousPrice;
import com.ez2find.model.Site;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Owner
 */
@Stateless
public class HousPriceManagerBean implements HousPriceManagerLocal {

    @PersistenceContext
    private EntityManager em;

    public void create(HousPrice housPricePrice) throws Exception {
        em.persist(housPricePrice);
    }

    public void update(HousPrice housPricePrice) throws Exception {
        em.merge(housPricePrice);
    }

    public HousPrice merge(HousPrice housPricePrice) throws Exception {
        return em.merge(housPricePrice);
    }

    public void delete(HousPrice housPricePrice) throws Exception {
        housPricePrice = em.merge(housPricePrice);
        em.remove(housPricePrice);
    }

    public HousPrice find(long id) {
        return em.find(HousPrice.class, id);
    }

    public List<HousPrice> listAll() {
        Query query = em.createNamedQuery("listAllHousPrices");
        List<HousPrice> result = query.getResultList();
        return result;
    }

    public double priceSiteHousCategorie(Site site, CategoriaInmobiliario housCategorie) {
        try {
            Query query = em.createNamedQuery("priceSiteHousCategorie");
            query.setParameter("site", site);
            query.setParameter("housCategorie", housCategorie);
            double result = (Double) query.getSingleResult();
            return result;
        } catch (Exception ex) {
            return 0;
        }
    }
}
